<template>
  <Dialog v-model="dialogVisible" :title="dialogTitle" class="enhanced-dialog" width="60%">
    <!-- 弹窗头部 -->
    <div class="dialog-header">
      <div class="header-icon">
        <Icon icon="ep:menu" />
      </div>
      <div class="header-content">
        <h4 class="dialog-title">{{ dialogTitle }}</h4>
        <p class="dialog-subtitle">菜单信息管理</p>
      </div>
    </div>

    <!-- 表单内容 -->
    <div class="form-container">
      <el-form
        ref="formRef"
        v-loading="formLoading"
        :model="formData"
        :rules="formRules"
        label-width="100px"
        class="enhanced-form"
      >
        <!-- 基本信息 -->
        <div class="form-section">
          <div class="section-title">
            <Icon icon="ep:info-filled" class="section-icon" />
            <span>基本信息</span>
          </div>

          <el-form-item label="上级菜单" class="form-item">
            <el-tree-select
              v-model="formData.parentId"
              :data="menuTree"
              :default-expanded-keys="[0]"
              :props="defaultProps"
              check-strictly
              node-key="id"
              class="enhanced-tree-select"
            >
              <template #prefix>
                <Icon icon="ep:menu" />
              </template>
            </el-tree-select>
          </el-form-item>

          <el-form-item label="菜单名称" prop="name" class="form-item">
            <el-input
              v-model="formData.name"
              clearable
              placeholder="请输入菜单名称"
              class="enhanced-input"
            >
              <template #prefix>
                <Icon icon="ep:collection-tag" />
              </template>
            </el-input>
          </el-form-item>

          <el-form-item label="菜单类型" prop="type" class="form-item">
            <el-radio-group v-model="formData.type" class="enhanced-radio-group">
              <el-radio-button
                v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_MENU_TYPE)"
                :key="dict.label"
                :label="dict.value"
                class="enhanced-radio-button"
              >
                {{ dict.label }}
              </el-radio-button>
            </el-radio-group>
          </el-form-item>

          <el-form-item v-if="formData.type !== 3" label="菜单图标" class="form-item">
            <IconSelect v-model="formData.icon" clearable class="enhanced-icon-select" />
          </el-form-item>

          <el-form-item v-if="formData.type !== 3" label="路由地址" prop="path" class="form-item">
            <template #label>
              <Tooltip
                message="访问的路由地址，如：`user`。如需外网地址时，则以 `http(s)://` 开头"
                title="路由地址"
              />
            </template>
            <el-input
              v-model="formData.path"
              clearable
              placeholder="请输入路由地址"
              class="enhanced-input"
            >
              <template #prefix>
                <Icon icon="ep:link" />
              </template>
            </el-input>
          </el-form-item>

          <el-form-item
            v-if="formData.type === 2"
            label="组件地址"
            prop="component"
            class="form-item"
          >
            <el-input
              v-model="formData.component"
              clearable
              placeholder="例如说：system/user/index"
              class="enhanced-input"
            >
              <template #prefix>
                <Icon icon="ep:folder" />
              </template>
            </el-input>
          </el-form-item>

          <el-form-item
            v-if="formData.type === 2"
            label="组件名字"
            prop="componentName"
            class="form-item"
          >
            <el-input
              v-model="formData.componentName"
              clearable
              placeholder="例如说：SystemUser"
              class="enhanced-input"
            >
              <template #prefix>
                <Icon icon="ep:document" />
              </template>
            </el-input>
          </el-form-item>

          <el-form-item
            v-if="formData.type !== 1"
            label="权限标识"
            prop="permission"
            class="form-item"
          >
            <template #label>
              <Tooltip
                message="Controller 方法上的权限字符，如：@PreAuthorize(`@ss.hasPermission('system:user:list')`)"
                title="权限标识"
              />
            </template>
            <el-input
              v-model="formData.permission"
              clearable
              placeholder="请输入权限标识"
              class="enhanced-input"
            >
              <template #prefix>
                <Icon icon="ep:key" />
              </template>
            </el-input>
          </el-form-item>

          <el-form-item label="显示排序" prop="sort" class="form-item">
            <el-input-number
              v-model="formData.sort"
              :min="0"
              clearable
              controls-position="right"
              class="enhanced-input-number"
            />
          </el-form-item>
        </div>

        <!-- 状态设置 -->
        <div class="form-section">
          <div class="section-title">
            <Icon icon="ep:setting" class="section-icon" />
            <span>状态设置</span>
          </div>

          <el-form-item label="菜单状态" prop="status" class="form-item">
            <el-radio-group v-model="formData.status" class="enhanced-radio-group">
              <el-radio
                v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
                :key="dict.label"
                :label="dict.value"
                class="enhanced-radio"
              >
                <Icon
                  :icon="dict.value === 0 ? 'ep:check' : 'ep:close'"
                  class="radio-icon"
                  :class="dict.value === 0 ? 'success' : 'danger'"
                />
                {{ dict.label }}
              </el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item
            v-if="formData.type !== 3"
            label="显示状态"
            prop="visible"
            class="form-item"
          >
            <template #label>
              <Tooltip
                message="选择隐藏时，路由将不会出现在侧边栏，但仍然可以访问"
                title="显示状态"
              />
            </template>
            <el-radio-group v-model="formData.visible" class="enhanced-radio-group">
              <el-radio key="true" :label="true" border class="enhanced-radio-border">
                <Icon icon="ep:view" class="radio-icon success" />
                显示
              </el-radio>
              <el-radio key="false" :label="false" border class="enhanced-radio-border">
                <Icon icon="ep:hide" class="radio-icon danger" />
                隐藏
              </el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item
            v-if="formData.type !== 3"
            label="总是显示"
            prop="alwaysShow"
            class="form-item"
          >
            <template #label>
              <Tooltip
                message="选择不是时，当该菜单只有一个子菜单时，不展示自己，直接展示子菜单"
                title="总是显示"
              />
            </template>
            <el-radio-group v-model="formData.alwaysShow" class="enhanced-radio-group">
              <el-radio key="true" :label="true" border class="enhanced-radio-border">
                <Icon icon="ep:check" class="radio-icon success" />
                总是
              </el-radio>
              <el-radio key="false" :label="false" border class="enhanced-radio-border">
                <Icon icon="ep:close" class="radio-icon danger" />
                不是
              </el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item
            v-if="formData.type === 2"
            label="缓存状态"
            prop="keepAlive"
            class="form-item"
          >
            <template #label>
              <Tooltip
                message="选择缓存时，则会被 `keep-alive` 缓存，必须填写「组件名称」字段"
                title="缓存状态"
              />
            </template>
            <el-radio-group v-model="formData.keepAlive" class="enhanced-radio-group">
              <el-radio key="true" :label="true" border class="enhanced-radio-border">
                <Icon icon="ep:collection" class="radio-icon success" />
                缓存
              </el-radio>
              <el-radio key="false" :label="false" border class="enhanced-radio-border">
                <Icon icon="ep:delete" class="radio-icon danger" />
                不缓存
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </div>
      </el-form>
    </div>

    <!-- 弹窗底部 -->
    <template #footer>
      <div class="dialog-footer">
        <el-button :disabled="formLoading" type="primary" @click="submitForm" class="submit-btn">
          <Icon icon="ep:check" class="btn-icon" />
          确 定
        </el-button>
        <el-button @click="dialogVisible = false" class="cancel-btn">
          <Icon icon="ep:close" class="btn-icon" />
          取 消
        </el-button>
      </div>
    </template>
  </Dialog>
</template>

<script lang="ts" setup>
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import * as MenuApi from '@/api/system/menu'
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
import { CommonStatusEnum, SystemMenuTypeEnum } from '@/utils/constants'
import { defaultProps, handleTree } from '@/utils/tree'

defineOptions({ name: 'SystemMenuForm' })

const { wsCache } = useCache()
const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗

const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const formType = ref('') // 表单的类型：create - 新增；update - 修改
const formData = ref({
  id: 0,
  name: '',
  permission: '',
  type: SystemMenuTypeEnum.DIR,
  sort: Number(undefined),
  parentId: 0,
  path: '',
  icon: '',
  component: '',
  componentName: '',
  status: CommonStatusEnum.ENABLE,
  visible: true,
  keepAlive: true,
  alwaysShow: true
})
const formRules = reactive({
  name: [{ required: true, message: '菜单名称不能为空', trigger: 'blur' }],
  sort: [{ required: true, message: '菜单顺序不能为空', trigger: 'blur' }],
  path: [{ required: true, message: '路由地址不能为空', trigger: 'blur' }],
  status: [{ required: true, message: '状态不能为空', trigger: 'blur' }]
})
const formRef = ref() // 表单 Ref

/** 打开弹窗 */
const open = async (type: string, id?: number, parentId?: number) => {
  dialogVisible.value = true
  dialogTitle.value = t('action.' + type)
  formType.value = type
  resetForm()
  if (parentId) {
    formData.value.parentId = parentId
  }
  // 修改时，设置数据
  if (id) {
    formLoading.value = true
    try {
      formData.value = await MenuApi.getMenu(id)
    } finally {
      formLoading.value = false
    }
  }
  // 获得菜单列表
  await getTree()
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

/** 提交表单 */
const emit = defineEmits(['success']) // 定义 success 事件，用于操作成功后的回调
const submitForm = async () => {
  // 校验表单
  if (!formRef) return
  const valid = await formRef.value.validate()
  if (!valid) return
  // 提交请求
  formLoading.value = true
  try {
    if (
      formData.value.type === SystemMenuTypeEnum.DIR ||
      formData.value.type === SystemMenuTypeEnum.MENU
    ) {
      if (!isExternal(formData.value.path)) {
        if (formData.value.parentId === 0 && formData.value.path.charAt(0) !== '/') {
          message.error('路径必须以 / 开头')
          return
        } else if (formData.value.parentId !== 0 && formData.value.path.charAt(0) === '/') {
          message.error('路径不能以 / 开头')
          return
        }
      }
    }
    const data = formData.value as unknown as MenuApi.MenuVO
    if (formType.value === 'create') {
      await MenuApi.createMenu(data)
      message.success(t('common.createSuccess'))
    } else {
      await MenuApi.updateMenu(data)
      message.success(t('common.updateSuccess'))
    }
    dialogVisible.value = false
    // 发送操作成功的事件
    emit('success')
  } finally {
    formLoading.value = false
    // 清空，从而触发刷新
    wsCache.delete(CACHE_KEY.ROLE_ROUTERS)
  }
}

/** 获取下拉框[上级菜单]的数据  */
const menuTree = ref<Tree[]>([]) // 树形结构
const getTree = async () => {
  menuTree.value = []
  const res = await MenuApi.getSimpleMenusList()
  let menu: Tree = { id: 0, name: '主类目', children: [] }
  menu.children = handleTree(res)
  menuTree.value.push(menu)
}

/** 重置表单 */
const resetForm = () => {
  formData.value = {
    id: 0,
    name: '',
    permission: '',
    type: SystemMenuTypeEnum.DIR,
    sort: Number(undefined),
    parentId: 0,
    path: '',
    icon: '',
    component: '',
    componentName: '',
    status: CommonStatusEnum.ENABLE,
    visible: true,
    keepAlive: true,
    alwaysShow: true
  }
  formRef.value?.resetFields()
}

/** 判断 path 是不是外部的 HTTP 等链接 */
const isExternal = (path: string) => {
  return /^(https?:|mailto:|tel:)/.test(path)
}
</script>

<style lang="scss" scoped>
// 主题色变量
$primary-color: #0052cc;
$primary-light: rgba(0, 82, 204, 0.1);
$primary-border: rgba(0, 82, 204, 0.3);
$success-color: #67c23a;
$warning-color: #e6a23c;
$danger-color: #f56c6c;
$info-color: #909399;
$text-primary: #303133;
$text-regular: #606266;
$text-secondary: #909399;
$text-placeholder: #c0c4cc;
$border-color: #dcdfe6;
$border-light: #e4e7ed;
$bg-color: #f5f7fa;
$shadow-light: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
$shadow-base:
  0 2px 4px rgba(0, 0, 0, 0.12),
  0 0 6px rgba(0, 0, 0, 0.04);
$border-radius: 12px;
$border-radius-small: 8px;

/* 弹窗样式 */
.enhanced-dialog {
  :deep(.el-dialog) {
    border-radius: $border-radius;
    overflow: hidden;

    @media (max-width: 768px) {
      width: 95% !important;
      margin: 0 auto;
    }
  }

  :deep(.el-dialog__header) {
    padding: 0;
    border-bottom: none;
  }

  :deep(.el-dialog__body) {
    padding: 0;
  }

  :deep(.el-dialog__footer) {
    padding: 0;
    border-top: none;
  }

  :deep(.el-dialog__headerbtn) {
    top: 16px;
    right: 16px;
    z-index: 10;

    .el-dialog__close {
      color: white;
      font-size: 18px;

      &:hover {
        color: rgba(255, 255, 255, 0.8);
      }
    }
  }
}

/* 弹窗头部 */
.dialog-header {
  display: flex;
  align-items: center;
  padding: 20px 24px;
  background: linear-gradient(135deg, $primary-color 0%, #1d4ed8 100%);
  color: white;

  @media (max-width: 768px) {
    padding: 16px 20px;
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }
}

.header-icon {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: $border-radius-small;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;

  @media (max-width: 768px) {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
}

.header-content {
  flex: 1;
  margin-left: 12px;

  @media (max-width: 768px) {
    margin-left: 0;
  }
}

.dialog-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 4px 0;

  @media (max-width: 768px) {
    font-size: 16px;
  }
}

.dialog-subtitle {
  font-size: 13px;
  opacity: 0.9;
  margin: 0;

  @media (max-width: 768px) {
    font-size: 12px;
  }
}

/* 表单容器 */
.form-container {
  padding: 24px;
  background: white;
  max-height: 70vh;
  overflow-y: auto;

  @media (max-width: 768px) {
    padding: 16px;
    max-height: 60vh;
  }

  /* 滚动条美化 */
  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
  }

  &::-webkit-scrollbar-thumb {
    background: rgba(0, 82, 204, 0.3);
    border-radius: 3px;
    transition: all 0.3s ease;

    &:hover {
      background: rgba(0, 82, 204, 0.5);
    }
  }
}

.enhanced-form {
  .form-section {
    margin-bottom: 32px;

    &:last-child {
      margin-bottom: 0;
    }

    @media (max-width: 768px) {
      margin-bottom: 24px;
    }
  }

  .section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid $primary-light;
    font-size: 16px;
    font-weight: 600;
    color: $text-primary;

    @media (max-width: 768px) {
      font-size: 14px;
      margin-bottom: 16px;
      padding-bottom: 8px;
    }
  }

  .section-icon {
    color: $primary-color;
    font-size: 18px;

    @media (max-width: 768px) {
      font-size: 16px;
    }
  }

  .form-item {
    margin-bottom: 20px;

    @media (max-width: 768px) {
      margin-bottom: 16px;
    }

    :deep(.el-form-item__label) {
      font-weight: 600;
      color: $text-regular;
      padding-bottom: 8px;

      @media (max-width: 768px) {
        font-size: 14px;
        width: 100% !important;
        text-align: left !important;
        margin-bottom: 8px;
      }
    }

    :deep(.el-form-item__content) {
      @media (max-width: 768px) {
        margin-left: 0 !important;
      }
    }
  }

  // H5适配：表单项垂直布局
  @media (max-width: 768px) {
    :deep(.el-form-item) {
      display: block;
    }
  }
}

/* 输入框样式 */
.enhanced-input {
  :deep(.el-input__wrapper) {
    border-radius: $border-radius-small;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;
    padding: 12px 16px;

    &:hover {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
    }

    &.is-focus {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.2);
      border-color: $primary-color;
    }
  }
}

/* 数字输入框样式 */
.enhanced-input-number {
  width: 100%;

  :deep(.el-input__wrapper) {
    border-radius: $border-radius-small;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;
    padding: 12px 16px;

    &:hover {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
    }

    &.is-focus {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.2);
      border-color: $primary-color;
    }
  }

  :deep(.el-input-number__increase),
  :deep(.el-input-number__decrease) {
    border: none;
    background: $primary-light;
    color: $primary-color;
    border-radius: 4px;
    transition: all 0.3s ease;

    &:hover {
      background: $primary-color;
      color: white;
    }
  }
}

/* 树形选择器样式 */
.enhanced-tree-select {
  width: 100%;

  :deep(.el-select__wrapper) {
    border-radius: $border-radius-small;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;
    padding: 8px 16px;

    &:hover {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
    }

    &.is-focused {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.2);
      border-color: $primary-color;
    }
  }

  :deep(.el-tree-select__popper) {
    border-radius: $border-radius-small;
    box-shadow: $shadow-light;
    border: 1px solid $border-light;

    .el-tree {
      .el-tree-node {
        .el-tree-node__content {
          border-radius: 6px;
          margin: 2px 4px;
          transition: all 0.3s ease;

          &:hover {
            background: $primary-light;
            color: $primary-color;
          }
        }

        &.is-current {
          .el-tree-node__content {
            background: $primary-color;
            color: white;
          }
        }
      }
    }
  }
}

/* 图标选择器样式 */
.enhanced-icon-select {
  :deep(.el-input__wrapper) {
    border-radius: $border-radius-small;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;
    padding: 12px 16px;

    &:hover {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
    }

    &.is-focus {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.2);
      border-color: $primary-color;
    }
  }
}

/* 单选按钮组样式 */
.enhanced-radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;

  @media (max-width: 768px) {
    flex-direction: column;
    gap: 8px;
  }
}

.enhanced-radio-button {
  :deep(.el-radio-button__inner) {
    border-radius: $border-radius-small;
    border: 2px solid $border-color;
    background: white;
    color: $text-regular;
    font-weight: 500;
    transition: all 0.3s ease;
    padding: 8px 16px;

    &:hover {
      border-color: $primary-color;
      color: $primary-color;
      background: $primary-light;
    }
  }

  :deep(.el-radio-button__original:checked + .el-radio-button__inner) {
    background: $primary-color;
    border-color: $primary-color;
    color: white;
    box-shadow: 0 2px 8px rgba(0, 82, 204, 0.3);
  }
}

.enhanced-radio {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-right: 20px;
  margin-bottom: 8px;

  @media (max-width: 768px) {
    margin-right: 0;
    margin-bottom: 12px;
  }

  :deep(.el-radio__input) {
    .el-radio__inner {
      border-color: $primary-border;
      transition: all 0.3s ease;

      &:hover {
        border-color: $primary-color;
      }
    }

    &.is-checked {
      .el-radio__inner {
        background-color: $primary-color;
        border-color: $primary-color;
      }
    }
  }

  :deep(.el-radio__label) {
    font-weight: 500;
    color: $text-regular;
    display: flex;
    align-items: center;
    gap: 4px;
  }
}

.enhanced-radio-border {
  border: 2px solid $border-color;
  border-radius: $border-radius-small;
  padding: 8px 12px;
  transition: all 0.3s ease;
  margin-right: 12px;
  margin-bottom: 8px;

  &:hover {
    border-color: $primary-color;
    background: $primary-light;
  }

  :deep(.el-radio__input.is-checked) {
    & + .el-radio__label {
      color: $primary-color;
    }
  }

  &.is-checked {
    border-color: $primary-color;
    background: $primary-light;
  }

  @media (max-width: 768px) {
    margin-right: 0;
    margin-bottom: 12px;
    width: 100%;
    text-align: center;
  }
}

.radio-icon {
  font-size: 14px;

  &.success {
    color: $success-color;
  }

  &.danger {
    color: $danger-color;
  }
}

/* 弹窗底部 */
.dialog-footer {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 20px 24px;
  background: #fafbff;
  border-top: 1px solid $border-light;

  @media (max-width: 768px) {
    padding: 16px 20px;
    flex-direction: column;
  }
}

.submit-btn {
  background: linear-gradient(135deg, $primary-color 0%, #1d4ed8 100%);
  border: none;
  border-radius: $border-radius-small;
  padding: 12px 24px;
  font-weight: 500;
  color: white;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 6px;

  &:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 82, 204, 0.3);
  }

  &:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
  }

  @media (max-width: 768px) {
    width: 100%;
    justify-content: center;
  }

  .btn-icon {
    font-size: 14px;
  }
}

.cancel-btn {
  border: 2px solid $border-color;
  color: $text-regular;
  border-radius: $border-radius-small;
  padding: 12px 24px;
  font-weight: 500;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 6px;

  &:hover {
    border-color: $primary-color;
    color: $primary-color;
    background: $primary-light;
  }

  @media (max-width: 768px) {
    width: 100%;
    justify-content: center;
  }

  .btn-icon {
    font-size: 14px;
  }
}

/* 加载状态优化 */
:deep(.el-loading-mask) {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(2px);

  .el-loading-spinner {
    .path {
      stroke: $primary-color;
    }
  }
}

/* 深色模式适配 */
@media (prefers-color-scheme: dark) {
  .form-container {
    background: #374151;
  }

  .dialog-footer {
    background: #4b5563;
    border-color: #6b7280;
  }

  .section-title {
    color: #f9fafb;
    border-color: rgba(96, 165, 250, 0.3);
  }

  .enhanced-form {
    .form-item {
      :deep(.el-form-item__label) {
        color: #d1d5db;
      }
    }
  }

  .enhanced-input,
  .enhanced-tree-select,
  .enhanced-icon-select,
  .enhanced-input-number {
    :deep(.el-input__wrapper),
    :deep(.el-select__wrapper) {
      background: #4b5563;
      border-color: #6b7280;

      .el-input__inner {
        color: #f9fafb;
      }
    }
  }

  .enhanced-input-number {
    :deep(.el-input-number__increase),
    :deep(.el-input-number__decrease) {
      background: rgba(96, 165, 250, 0.1);
      color: #60a5fa;

      &:hover {
        background: #60a5fa;
        color: white;
      }
    }
  }

  .enhanced-tree-select {
    :deep(.el-tree-select__popper) {
      background: #4b5563;
      border-color: #6b7280;

      .el-tree {
        .el-tree-node {
          .el-tree-node__content {
            color: #f9fafb;

            &:hover {
              background: rgba(96, 165, 250, 0.1);
              color: #60a5fa;
            }
          }

          &.is-current {
            .el-tree-node__content {
              background: #60a5fa;
              color: white;
            }
          }
        }
      }
    }
  }

  .enhanced-radio-button {
    :deep(.el-radio-button__inner) {
      background: #4b5563;
      border-color: #6b7280;
      color: #f9fafb;

      &:hover {
        border-color: #60a5fa;
        color: #60a5fa;
        background: rgba(96, 165, 250, 0.1);
      }
    }

    :deep(.el-radio-button__original:checked + .el-radio-button__inner) {
      background: #60a5fa;
      border-color: #60a5fa;
      color: white;
    }
  }

  .enhanced-radio {
    :deep(.el-radio__input) {
      .el-radio__inner {
        border-color: rgba(96, 165, 250, 0.3);
        background: #4b5563;

        &:hover {
          border-color: #60a5fa;
        }
      }

      &.is-checked {
        .el-radio__inner {
          background-color: #60a5fa;
          border-color: #60a5fa;
        }
      }
    }

    :deep(.el-radio__label) {
      color: #f9fafb;
    }
  }

  .enhanced-radio-border {
    background: #4b5563;
    border-color: #6b7280;
    color: #f9fafb;

    &:hover {
      border-color: #60a5fa;
      background: rgba(96, 165, 250, 0.1);
    }

    &.is-checked {
      border-color: #60a5fa;
      background: rgba(96, 165, 250, 0.1);
    }
  }

  .radio-icon {
    &.success {
      color: #34d399;
    }

    &.danger {
      color: #f87171;
    }
  }
}

/* 响应式优化 */
@media (max-width: 480px) {
  .dialog-header {
    padding: 12px 16px;
  }

  .form-container {
    padding: 12px;
  }

  .enhanced-form {
    .form-section {
      margin-bottom: 20px;
    }

    .section-title {
      font-size: 13px;
      margin-bottom: 12px;
      padding-bottom: 6px;
    }

    .form-item {
      margin-bottom: 12px;

      :deep(.el-form-item__label) {
        font-size: 13px;
      }
    }
  }

  .enhanced-radio-group {
    gap: 6px;
  }

  .enhanced-radio {
    margin-bottom: 8px;
  }

  .enhanced-radio-border {
    padding: 6px 10px;
    margin-bottom: 8px;
  }

  .dialog-footer {
    padding: 12px 16px;
    gap: 8px;
  }
}
</style>
